<layout name="layout" />
<div class="list-div" id="listDiv">
	<form method="post" action="__SELF__">
		<table cellpadding="3" cellspacing="1" class="table table-hover">

			<tr class="success">
				<?php foreach($gaData as $k=>$v): ?>
				<th width="120"><?php echo $k; ?></th>
				<?php endforeach; ?>
				<th width="120">库存量</th>
				<th width="60">操作</th>
			</tr>
			<?php if($gnData): ?>
			<?php foreach($gnData as $key => $val): ?>
			<tr class="tron">
				<?php
					$gaCount = count($gaData);
					foreach($gaData as $k => $v): ?>
						<td>
							<select name="goods_attr_id[]">
								<option value="">请选择</option>
								<?php foreach($v as $k1 => $v1):
									$_attr = explode(',',$val['goods_attr_id']);
									if(in_array($v1['id'],$_attr)){
										$select = 'selected="selected"';
									} else {
										$select = '';
								}
								?>
									<option <?php echo $select; ?>value="<?php echo $v1['id']; ?>"><?php echo $v1['attr_value']; ?></option>
								<?php endforeach; ?>
							</select>
						</td>
				<?php endforeach; ?>
				<td><input type="text" name="goods_number[]" value="<?php echo $val['goods_number']; ?>"/></td>
				<td><input type="button" onclick="addNewTr(this);" value="<?php echo $key == 0 ? '+' : '-'; ?>"/></td>
			</tr>
			<?php endforeach; ?>
			<?php else: ?>
			<tr class="tron">
				<?php
					$gaCount = count($gaData);
					foreach($gaData as $k => $v): ?>
				<td>
					<select name="goods_attr_id[]">
						<option value="">请选择</option>
						<?php foreach($v as $k1 => $v1):?>
							<option value="<?php echo $v1['id']; ?>"><?php echo $v1['attr_value']; ?></option>
						<?php endforeach; ?>
					</select>
				</td>
				<?php endforeach; ?>
				<td><input type="text" name="goods_number[]" /></td>
				<td><input type="button" onclick="addNewTr(this);" value="+"/></td>
			</tr>
			<?php endif; ?>
			<tr id="submit">
				<td align="center" colspan="<?php echo $gaCount+2; ?>"><input type="submit" value="提交"/></td>
			</tr>
		</table>
	</form>
</div>
<script type="text/javascript">
	function addNewTr(btn) {
		var tr = $(btn).parent().parent();
		if($(btn).val() == "+"){
			var newTr = tr.clone();
			newTr.find(":button").val("-");
			$("#submit").before(newTr);
		} else {
			tr.remove();
		}
	}
</script>

<script src="__PUBLIC__/Admin/Js/tron.js"></script>
<link href="__PUBLIC__/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="__PUBLIC__/bootstrap/js/bootstrap.min.js"></script>